import React from 'react';
import wamp from './utils/wamp';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      message: '',
    };
    this.wamp = wamp;
    this.handleMessageChange = this.handleMessageChange.bind(this);
    this.send = this.send.bind(this);
  }

  componentDidMount() {
    this.wamp.open();
  }

  handleMessageChange(event) {
    this.setState({
      message: event.target.value,
    });
  }

  send() {
    console.log(this.state.message);
    this.wamp.send(this.state.message);
  }

  render() {
    return <div className="wrap">
      <input type="text" value={this.state.message} onChange={this.handleMessageChange}/>
      <div>&nbsp;</div>
      <button onClick={this.send}>发送</button>
    </div>;
  }
};
